package com.hcrazy.manchester.app.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.joda.time.DateTime;

public class MD5Util {

	public static String fromStringToMD5(String str) throws NoSuchAlgorithmException,UnsupportedEncodingException {
		char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
				'A', 'B', 'C', 'D', 'E', 'F' };
		MessageDigest mdInst = MessageDigest.getInstance("MD5");
		mdInst.update(str.getBytes());
		byte[] md = mdInst.digest();
		int j = md.length;
		char chars[] = new char[j * 2];
		int k = 0;
		for (int i = 0; i < j; i++) {
			byte byte0 = md[i];
			chars[k++] = hexDigits[byte0 >>> 4 & 0xf];
			chars[k++] = hexDigits[byte0 & 0xf];
		}
		return new String(chars);
	}
	
	public static void main(String args[]){
		String pass = "1";
		try {
			System.out.println(MD5Util.fromStringToMD5(pass));
			DateTime dt = new DateTime(System.currentTimeMillis()); 
			
			System.out.println(dt.toString("yyyy-MM-dd HH:mm:ss"));
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
